package com.tao.aszx.manager.controller;


import com.github.pagehelper.PageInfo;
import com.tao.aszx.manager.service.SysUserService;
import com.tao.aszx.model.dto.system.SysRole;
import com.tao.aszx.model.dto.system.SysUserDto;
import com.tao.aszx.model.entity.system.SysUser;
import com.tao.aszx.model.vo.common.Result;
import com.tao.aszx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "用户管理")
@RequestMapping("/admin/system/sysUser")
public class SysUserController {


    @Autowired
    private SysUserService sysUserService ;

    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysRole>> findByPage(SysUserDto sysUserDto ,
                                                @PathVariable(value = "pageNum") Integer pageNum ,
                                                @PathVariable(value = "pageSize") Integer pageSize) {
        System.out.println(sysUserDto);
        PageInfo<SysUser> pageInfo = sysUserService.findByPage(sysUserDto , pageNum , pageSize) ;
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS) ;
    }

    @PutMapping(value = "/updateSysUser")
    public Result updateSysUser(@RequestBody SysUser sysUser) {
        int num = sysUserService.updateSysUser(sysUser) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }


    @PostMapping(value = "/saveSysUser")
    public Result saveSysUser(@RequestBody SysUser sysUser) {
        System.out.println();
        int num = sysUserService.saveSysUser(sysUser) ;
        if (! (num>0)){
            return Result.build(null , 209,"用户已存在");
        }
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @DeleteMapping(value = "/deleteSysUser/{id}")
    public Result deleteById(@PathVariable Integer id){
        sysUserService.deleteById(id) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

}

